package LeetCode.Leet100_199.Leet120_129.Leet121;

/**
 * @ClassName Solution_1
 * @Author 孙天赐
 * @Date 2025/10/28 8:39
 * @Description TODO: 方法一   贪心 1ms  100%
 */
class Solution_1 {
    public int maxProfit(int[] prices) {
        // 找到一个最小的购入点
        int low = Integer.MAX_VALUE;
        // res不断更新，直到数组循环完毕
        int res = 0;
        for (int i = 0; i < prices.length; i++) {
            low = Math.min(prices[i], low);
            res = Math.max(prices[i] - low, res);
        }
        return res;
    }
}